import request from '@/utils/request'
import type { RoleListResponseData, Role, MenuListResponseData } from './type'
enum API {
  GETROLELIST_URL = '/admin/acl/role/',
  SAVEROLE_URL = '/admin/acl/role/save',
  UPDATEROLE_URL = '/admin/acl/role/update',
  GETMENULIST_URL = '/admin/acl/permission/toAssign/',
  SETPERMISSION_URL = '/admin/acl/permission/doAssign',
  DELETEROLE_URL = '/admin/acl/role/remove/'
}
// 获取角色列表
export const getRoleListService = (
  page: number,
  limit: number,
  roleName: string
) =>
  request.get<any, RoleListResponseData>(
    API.GETROLELIST_URL + `${page}/${limit}?roleName=${roleName}`
  )

// 新增角色
export const addRoleService = (data: Role) =>
  request.post<any, any>(API.SAVEROLE_URL, data)

// 更新角色
export const updateRoleService = (data: Role) =>
  request.put<any, any>(API.UPDATEROLE_URL, data)

// 获取菜单列表
export const getMenuListService = (roleId: string) =>
  request.get<any, MenuListResponseData>(API.GETMENULIST_URL + roleId)

//分配权限
export const setPermissionService = (
  roleId: number | string,
  permissionId: number[] | string[]
) =>
  request.post<any, any>(
    API.SETPERMISSION_URL + `?roleId=${roleId}&permissionId=${permissionId}`
  )

// 删除角色
export const deleteRoleService = (id: string) =>
  request.delete<any, any>(API.DELETEROLE_URL + id)
